const { defineConfig } = require('@vue/cli-service')
const Mock = require('mockjs')
let { list, car } = Mock.mock({
  'list|30': [
    {
      id: '@id',
      img: '@image(180x120,@color,image)',
      title: '@ctitle(2)',
      word: '@cword(50)',
      'children|4': ["@image('100x100','@color','#FFF','yb')"],
    },
  ],
  'car|5': [
    {
      src: '@image(120x80,@color,image)',
      title: '@ctitle(2)',
      word: '@cword(20)',
      'price|10-100': 1,
      ischecked: false,
      count: 1,
    },
  ],
})
module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false,
  devServer: {
    setupMiddlewares(mid, { app }) {
      app.get('/api/list', (req, res) => {
        res.send({
          code: 200,
          list,
        })
      })
      app.get('/api/detail', (req, res) => {
        let { id } = req.query
        let item = list.find((item) => item.id === id)
        res.send({
          code: 200,
          item,
        })
      })
      app.get('/api/car', (req, res) => {
        res.send({
          code: 200,
          car,
        })
      })
      return mid
    },
  },
})
